package com.ddwl.wallet.controller;

import com.ddwl.common.annotation.Auth;
import com.ddwl.common.annotation.Submit;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.controller.BaseController;
import com.ddwl.schema.bo.base.PageBo;
import com.ddwl.schema.bo.wallet.ShopSubmitWithdrawBo;
import com.ddwl.schema.bo.wallet.WalletFlowQueryBo;
import com.ddwl.schema.bo.wallet.WithdrawListQueryBo;
import com.ddwl.schema.vo.base.PageVo;
import com.ddwl.schema.vo.base.RestVo;
import com.ddwl.schema.vo.wallet.*;
import com.ddwl.wallet.service.UserWalletService;
import com.ddwl.wallet.service.WithdrawChannelService;
import com.ddwl.wallet.service.WithdrawService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 类ShopWalletController.java的实现描述：TODO
 *
 * @author zach
 * @Date :2020-12-05 16:50.
 */
@Slf4j
@Api(tags = "店铺商户后台钱包操作接口")
@RequestMapping("/shop")
@RestController
@Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
public class ShopWalletController extends BaseController {

    @Resource
    private UserWalletService userWalletService;
    @Resource
    private WithdrawService withdrawService;
    @Resource
    private WithdrawChannelService withdrawChannelService;

    @PostMapping("/shopWalletTotal")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    @ApiOperation("查询店铺收益总数据")
    public RestVo<UserWalletMainReportVo> shopWalletTotal() {
        return RestVo.ok(userWalletService.getUserWalletReportVo(getUserId()));
    }

    @ApiOperation("查询店铺钱包变更流水")
    @PostMapping("/money/flow")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<PageVo<UserWalletFlowVo>> queryMoneyFlow(@RequestBody PageBo<WalletFlowQueryBo> bo) {
        if (bo.getParam() == null) {
            bo.setParam(new WalletFlowQueryBo());
        }
        bo.getParam().setUserId(getUserId());
        return RestVo.ok(userWalletService.queryMoneyFlow(bo));
    }


    @ApiOperation("查询用户钱包变更流水")
    @PostMapping("/money/userflow")
    @Auth(product = {BaseEnum.ProductEnum.WBM, BaseEnum.ProductEnum.WBM_OFFICE, BaseEnum.ProductEnum.BYTE_DANCE})
    public RestVo<PageVo<UserWalletFlowVo>> queryUserMoneyFlow(@RequestBody PageBo<WalletFlowQueryBo> bo) {
        if (bo.getParam() == null) {
            bo.setParam(new WalletFlowQueryBo());
        }
        bo.getParam().setUserId(getUserId());
        return RestVo.ok(userWalletService.queryMoneyFlow(bo));
    }

    @Submit
    @ApiOperation(value = "店铺提现申请提交")
    @PostMapping("/withdraw/submit")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<UserWalletVo> queryUserWithdrawChannel(@Valid @RequestBody ShopSubmitWithdrawBo submitBo) {
        submitBo.setUserId(getUserId());
        submitBo.setUserName(getUserNameNew());
        submitBo.setShopId(getShopId());
        submitBo.setShopName(getShopName());
        return RestVo.ok(withdrawService.shopSubmitWithdraw(submitBo));
    }

    @PostMapping("/userPage")
    @ApiOperation("查询当前登录店铺提现记录")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<PageVo<UserWithdrawRecordVo>> queryUserWithdrawRecord(@RequestBody PageBo<WithdrawListQueryBo> bo) {
        if (bo.getParam() == null) {
            bo.setParam(new WithdrawListQueryBo());
        }
        bo.getParam().setUserId(getUserId());
        return RestVo.ok(withdrawService.queryWithdrawRecord(bo));
    }

    @PostMapping("/bank")
    @ApiOperation("查询当前店铺绑定银行卡信息")
    @Auth(product = {BaseEnum.ProductEnum.SHOP_CONSOLE})
    public RestVo<WithdrawChannelVo> bankInfo() {
        return RestVo.ok(withdrawChannelService.queryShopChannel(getShopId()));
    }

}
